<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>weibo</title>
</head>
<body>
<h1>我的微博列表</h1>
<div>
    <div v-for="weibo in arr">
         <h3>{{weibo.content}}</h3>
        <p>发布于:{{weibo.created}}
            <a href="javascript:void(0)" @click="del(weibo.id)">删除</a></p>
    </div>
</div>
<!--引入vue和axios-->
<script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/2.6.14/vue.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="http://cdn.staticfile.org/moment.js/2.24.0/moment.js"></script>
<script>
    let v = new Vue({
        el:"body>div",
        data:{
            arr:[]
        },
        created:function (){
            //发请求获取当前用户发布的所有微博
            axios.get("/weibo/selectMyself").then(function (response){
                v.arr = response.data;
                for(let weibo of v.arr){
                    weibo.created = moment(weibo.created).format("YYYY年MM月DD日 HH:mm:ss");
                }
            });
        },
        methods:{
            del:function (id){
                //发请求从数据库中删除这条数据
                if (confirm("您确定要删除这条微博?")){
                    axios.get("/weibo/delete?id="+id).then(function (){
                            location.reload();
                    })
                }
            }
        }
    })
</script>
</body>
</html>